package com.gitee.core.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.google.common.io.Files;

import java.io.File;
import java.io.IOException;

/**
 * Created by zhang_tao6 on 2017-11-28.
 */

public class MyElasticJob implements SimpleJob {

    @Override
    public void execute(ShardingContext context) {
        System.out.println("shard======================================>"+context.getShardingItem());
        System.out.println("shard======================================>"+context.getShardingItem());
        System.out.println("shard======================================>"+context.getShardingItem());
        System.out.println("shard======================================>"+context.getShardingItem());
        System.out.println("shard======================================>"+context.getShardingItem());
        System.out.println("shard======================================>"+context.getShardingItem());
        System.out.println("shard======================================>"+context.getShardingItem());
        try {
            Files.write(("xx"+context.getShardingItem()).getBytes(),new File("D:/log.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        switch (context.getShardingItem()) {
            case 0:
                // do something by sharding item 0
                System.out.println("shard===>0");
                break;
            case 1:
                // do something by sharding item 1
                System.out.println("shard===>1");
                break;
            case 2:
                // do something by sharding item 2
                System.out.println("shard===>2");
                break;
            // case n: ...
        }
    }
}
